<template>
    <view :style="themeColor">
        <view class="page" >
    <view class="flex align-stretch benben-position-layout flex ApplyOpenInvoicessss_flex_0"    :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
            <view   class='flex align-center justify-between flex-sub ApplyOpenInvoicessss_fd0_0'      >
            <view   class='flex align-center ApplyOpenInvoicessss_fd0_0_c0'   @tap.stop="handleJumpDiy" data-type="back" data-url="1"   >
        <text class='fu-iconfont2  ApplyOpenInvoicessss_fd0_0_c0_c0'  >&#xE794;</text>
</view>
    <view   class='flex align-center'      >
        <text class='ApplyOpenInvoicessss_fd0_0_c1_c0'  >{{$t('申请开票')}}</text>
</view>
    <view   class='flex align-center ApplyOpenInvoicessss_fd0_0_c0'      >
        </view>
</view>

        </view>
<view :style="{height: (88+StatusBarRpx)+'rpx'}"  ></view>

 <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout ApplyOpenInvoicessss_flex_1"    >
            <view   class='flex flex-direction align-stretch ApplyOpenInvoicessss_fd1_0'      >
            <view   class='flex flex-wrap align-center justify-between ApplyOpenInvoicessss_fd1_0_c0'      >
        <text class='ApplyOpenInvoicessss_fd1_0_c0_c0'  >{{$t('发票类型')}}</text>
<text class='ApplyOpenInvoicessss_fd1_0_c0_c1'  >{{$t('电子发票')}}</text>
</view>
    <view   class='flex flex-wrap align-center ApplyOpenInvoicessss_fd1_0_c1'      >
        <text class='ApplyOpenInvoicessss_fd1_0_c1_c0'  >{{$t('发票信息')}}</text>
</view>
    <view   class='flex flex-wrap align-center ApplyOpenInvoicessss_fd1_0_c2'      >
        <text class='ApplyOpenInvoicessss_fd1_0_c2_c0'  >{{$t('抬头类型')}}</text>
    <benben-select-diy ref="showSelectPopup1689756647721" class-name='flex align-center flex'  :items.sync="type" v-model="dataMessage.type" :label.sync="type_la"  default-type="value" default-label="name" :allow-cancel='false' type="radio" :disabled='false'  >
    <template v-for = '(item,key0) in type'>
            <view v-if="item.isSelected"  class='flex align-center flex ApplyOpenInvoicessss_fd1_0_c2_c1_c0'  :key="key0" @tap="$refs.showSelectPopup1689756647721.tapHandle(key0)"     >
        <image class='ApplyOpenInvoicessss_fd1_0_c2_c1_c0_c0'  mode="aspectFit"  :src='STATIC_URL+"3.png"'></image>
<text class='ApplyOpenInvoicessss_fd1_0_c0_c1'  >{{item.name}}</text>
</view>    <view  v-else  class='flex align-center flex ApplyOpenInvoicessss_fd1_0_c2_c1_c0'  :key="key0" @tap="$refs.showSelectPopup1689756647721.tapHandle(key0)"     >
        <image class='ApplyOpenInvoicessss_fd1_0_c2_c1_c0_c0'  mode="aspectFit"  :src='STATIC_URL+"135.png"'></image>
<text class='ApplyOpenInvoicessss_fd1_0_c0_c1'  >{{item.name}}</text>
</view></template></benben-select-diy>
</view>
    <view   class='flex flex-wrap align-center ApplyOpenInvoicessss_fd1_0_c3'      >
        <image class='ApplyOpenInvoicessss_fd1_0_c3_c0'  mode="aspectFit"  :src='STATIC_URL+"282.png"'></image>
<text class='ApplyOpenInvoicessss_fd1_0_c3_c1'  >{{$t('发票抬头')}}</text>
<benben-input class='flex-sub ApplyOpenInvoicessss_fd1_0_c3_c2'   type="text" :placeholder="$t('发票抬头不能为空')" confirm-type="done" :maxlength="18" placeholder-style="color:#BFBFBF;font-size:32rpx"  v-model="dataMessage.username" />
</view>
    <view   class='flex flex-wrap align-center ApplyOpenInvoicessss_fd1_0_c3'    v-if= "dataMessage.type=='2'"  >
        <image class='ApplyOpenInvoicessss_fd1_0_c3_c0'  mode="aspectFit"  :src='STATIC_URL+"282.png"'></image>
<text class='ApplyOpenInvoicessss_fd1_0_c3_c1'  >{{$t('公司税号')}}</text>
<benben-input class='flex-sub ApplyOpenInvoicessss_fd1_0_c3_c2'   type="text" :placeholder="$t('企业单位税号不能为空')" confirm-type="done" :maxlength="20" placeholder-style="color:#BFBFBF;font-size:32rpx"  v-model="dataMessage.tax_number" />
</view>
    <view   class='flex flex-wrap align-center justify-between ApplyOpenInvoicessss_fd1_0_c0'      >
        <text class='ApplyOpenInvoicessss_fd1_0_c0_c0'  >{{$t('设置为默认抬头')}}</text>
        <benben-flex-switch-new class-name='flex flex'  v-model="is_tk" :disabled='false'   >
            <template v-slot:checked>
            
    <view   class='flex flex position-relative align-center'      >
        <image class='ApplyOpenInvoicessss_checkfd1_0_c5_c1_c0_c0'  mode="aspectFit"  :src='STATIC_URL+"3.png"'></image>
</view>

            </template>
            <template v-slot:unchecked>
            
    <view   class='flex flex position-relative justify-end align-center'      >
        <image class='ApplyOpenInvoicessss_noCheckfd1_0_c5_c1_c1_c0'  mode="aspectFit"  :src='STATIC_URL+"213.png"'></image>
</view>

            </template>
        </benben-flex-switch-new>
</view>
    <view   class='flex flex-wrap align-center ApplyOpenInvoicessss_fd1_0_c6'      >
        </view>
    <view   class='flex flex-wrap align-center justify-between ApplyOpenInvoicessss_fd1_0_c0'      >
        <text class='ApplyOpenInvoicessss_fd1_0_c0_c0'  >{{$t('发票内容')}}</text>
<text class='ApplyOpenInvoicessss_fd1_0_c0_c1'  >{{$t('商品明细')}}</text>
</view>
    <view   class='flex flex-wrap align-center ApplyOpenInvoicessss_fd1_0_c6'      >
        </view>
    <view   class='flex flex-wrap align-center ApplyOpenInvoicessss_fd1_0_c3'      >
        <image class='ApplyOpenInvoicessss_fd1_0_c3_c0'  mode="aspectFit"  :src='STATIC_URL+"282.png"'></image>
<text class='ApplyOpenInvoicessss_fd1_0_c3_c1'  >{{$t('联系方式')}}</text>
<benben-input class='flex-sub ApplyOpenInvoicessss_fd1_0_c3_c2'   type="number" :placeholder="$t('联系方式不能为空')" confirm-type="done" :maxlength="11" placeholder-style="color:#BFBFBF;font-size:32rpx"  v-model="dataMessage.mobile" />
</view>
    <view   class='flex flex-wrap align-center ApplyOpenInvoicessss_fd1_0_c3'      >
        <image class='ApplyOpenInvoicessss_fd1_0_c3_c0'  mode="aspectFit"  :src='STATIC_URL+"282.png"'></image>
<text class='ApplyOpenInvoicessss_fd1_0_c3_c1'  >{{$t('电子邮箱')}}</text>
<benben-input class='flex-sub ApplyOpenInvoicessss_fd1_0_c3_c2'   type="text" :placeholder="$t('电子邮箱不能为空')" confirm-type="done" :maxlength="32" placeholder-style="color:#BFBFBF;font-size:32rpx"  v-model="dataMessage.email" />
</view>
</view>
    <view   class='flex flex-wrap align-center justify-center ApplyOpenInvoicessss_fd1_1'      >
        <button class='ApplyOpenInvoicessss_fd1_1_c0'  @tap.stop="editAddFunc()"  >{{$t('提交')}}</button>
</view>
</view>
        

    
    
        </view>
    </view>
</template>
<script>
    import {validate} from '@/common/utils/validate.js'
    
    export default {
        components:{},
        
        
        data(){
			return {"type":[],"is_tk":false,"dataDetails":{"invite_code":"","address":"","address_code":"","hobby":"","tags":"","id":"","userlevel_id":"","mobile":"","real_name":"","avatar":"","account":"","email":"","birthday":"","gender":"","create_time":"","user_money":"","freeze_money":"","total_consumption_money":"","score":"","_mobile":"","coupon":"","collection_count":"","browse_count":"","total_money":"","certified":"","nickname":"","is_pay_password":"","follow_count":""},"type_la":"","dataMessage":{"user_nickname":"","username":"","tax_number":"","mobile":"","email":"","type":"","is_default":"","status":"","create_time":"","type_name":""},"id":""};
		},
		computed:{
            themeColor() {
              return this.$store.getters.themeColor
            },
            
		},
		watch:{},
		onLoad(options){
            let {id}=options
if (id !== undefined) this.id = id
this.getMessageFunc()
this.setTypeFunc()
		},
        onUnload() {
                
        },
		onReady(){
            
		},
		onShow(){
            
		},
		onHide(){
            
		},
		onResize(){
            
		},
		onPullDownRefresh(){
            
		},
		onReachBottom(e){
            
		},
		onPageScroll(e){
            
		},
		methods:{
                            //获取单个发票信息
                async getMessageFunc(){
                       this.dataMessage.type = '1';
    if( this.id!=''){
            //请求方法
    //数据验证
    
  let datadataMessage = await this.$api.get(global.apiUrls.post6442399c6fca9, {
    aid:this.id
  });
  
  if (datadataMessage.data.code != 1) {
    this.$message.info(datadataMessage.data.msg);
    return
  } 
  let infodataMessage = datadataMessage.data;
  this.dataMessage = infodataMessage.data
  
    if( this.dataMessage.is_default=='1'){
           this.is_tk = true;
    }
    else{
           this.is_tk = false;
    }
    }
                },
                //添加或编辑
                async editAddFunc(){
                    if (!this.dataMessage.username) {
    uni.showToast({
        title: global.i18n.t('请输入发票抬头'),
        mask: true,
        icon: 'none',
        duration: 1500
    });
    return;
}
if (!this.dataMessage.mobile) {
    uni.showToast({
        title: global.i18n.t('请输入联系方式'),
        mask: true,
        icon: 'none',
        duration: 1500
    });
    return;
}
if (!validate(this.dataMessage.mobile, 'phone')) {
    uni.showToast({
        title: global.i18n.t('请输入正确的联系方式'),
        mask: true,
        icon: 'none',
        duration: 1500
    });
    return false;
}
if (!this.dataMessage.email) {
    uni.showToast({
        title: global.i18n.t('请输入电子邮箱'),
        mask: true,
        icon: 'none',
        duration: 1500
    });
    return;
}
if (!validate(this.dataMessage.email, 'email')) {
    uni.showToast({
        title: global.i18n.t('请输入正确的邮箱'),
        mask: true,
        icon: 'none',
        duration: 1500
    });
    return false;
}
if (this.dataMessage.type == 2) {
    if (!this.dataMessage.tax_number) return
    uni.showToast({
        title: global.i18n.t('请输入公司税号'),
        mask: true,
        icon: 'none',
        duration: 1500
    });
}
this.dataMessage.is_default = this.is_tk ? 1 : 0;
this.dataMessage.aid = this.id;
uni.setStorageSync('invoice', this.dataMessage);
this.$urouter.navigateTo(`/pages/fp/invoiceConfirm/invoiceConfirm?aid=${this.id}`);
                },
                //设置type
                 setTypeFunc(){
                        this.type = [{
    "name": global.i18n.t("个人"),
    "value": "1",
    "image": ""
}, {
    "name": global.i18n.t("企业"),
    "value": "2",
    "image": ""
}]
                }
		}
    };
</script> 
<style lang="scss" scoped>
           .page{
            width: 100vw;
            overflow-x: hidden;
            min-height: calc(100vh - var(--window-bottom));
            background:#F8F8F8;background-size: 100% auto;
        }
    .ApplyOpenInvoicessss_flex_0{
        background:#fff;width:750rpx;height:88rpx;overflow:hidden;z-index:10;top:0rpx;background-size:100% auto !important;
    }
    .ApplyOpenInvoicessss_fd0_0_c1_c0{
        font-size:36rpx;font-weight:500;color:#333;
    }
    .ApplyOpenInvoicessss_fd0_0_c0_c0{
        font-size:32rpx;font-weight:500;color:#333;
    }
    .ApplyOpenInvoicessss_fd0_0_c0{
        width:180rpx;
    }
    .ApplyOpenInvoicessss_fd0_0{
        padding:0rpx 32rpx 0rpx 32rpx;line-height:88rpx;
    }
    .ApplyOpenInvoicessss_flex_1{
        margin:0rpx 0rpx 32rpx 0rpx;
    }
    .ApplyOpenInvoicessss_fd1_1_c0{
        background:var(--benbenbgColor7);border-radius:44rpx 44rpx 44rpx 44rpx;font-size:32rpx;color:var(--benbenFontColor3);width:686rpx;height:88rpx;line-height:88rpx;font-weight:400;
    }
    .ApplyOpenInvoicessss_fd1_1{
        position:fixed;left:0rpx;bottom:calc(40rpx + var(--window-bottom));width:750rpx;
    }
    .ApplyOpenInvoicessss_fd1_0_c6{
        background:rgba(248, 248, 248, 1);height:20rpx;background-size:100% auto !important;
    }
    .ApplyOpenInvoicessss_noCheckfd1_0_c5_c1_c1_c0{
        border-radius:24rpx 24rpx 24rpx 24rpx;width:36rpx;height:36rpx;
    }
    .ApplyOpenInvoicessss_checkfd1_0_c5_c1_c0_c0{
        width:36rpx;height:36rpx;border-radius:24rpx 24rpx 24rpx 24rpx;
    }
    .ApplyOpenInvoicessss_fd1_0_c3_c2{
        line-height:45rpx;font-size:32rpx;font-weight:400;color:#333;text-align:right;
    }
    .ApplyOpenInvoicessss_fd1_0_c3_c1{
        line-height:45rpx;font-size:32rpx;font-weight:500;color:#333333;margin:0rpx 24rpx 0rpx 0rpx;
    }
    .ApplyOpenInvoicessss_fd1_0_c3_c0{
        width:12rpx;height:12rpx;border-radius:0rpx 0rpx 0rpx 0rpx;margin:0rpx 8rpx 0rpx 0rpx;
    }
    .ApplyOpenInvoicessss_fd1_0_c3{
        border-bottom:1px solid #eee;margin:0rpx 32rpx 0rpx 32rpx;padding:32rpx 0rpx 32rpx 0rpx;
    }
    .ApplyOpenInvoicessss_fd1_0_c2_c1_c0_c0{
        width:36rpx;height:36rpx;border-radius:18rpx 18rpx 18rpx 18rpx;margin:0rpx 24rpx 0rpx 0rpx;
    }
    .ApplyOpenInvoicessss_fd1_0_c2_c1_c0{
        margin:0rpx 0rpx 0rpx 48rpx;
    }
    .ApplyOpenInvoicessss_fd1_0_c2_c0{
        line-height:45rpx;font-size:32rpx;font-weight:500;color:#333333;margin:0rpx auto 0rpx 0rpx;
    }
    .ApplyOpenInvoicessss_fd1_0_c2{
        border-bottom:1px solid #eee;margin:0rpx 32rpx 0rpx 32rpx;padding:32rpx 0rpx 32rpx 20rpx;
    }
    .ApplyOpenInvoicessss_fd1_0_c1_c0{
        color:var(--benbenFontColor5);font-size:28rpx;font-weight:700;line-height:40rpx;
    }
    .ApplyOpenInvoicessss_fd1_0_c1{
        background:rgba(0, 142, 77, 0.1);background-size:100% auto !important;padding:24rpx 52rpx 24rpx 52rpx;
    }
    .ApplyOpenInvoicessss_fd1_0_c0_c1{
        line-height:45rpx;font-size:32rpx;font-weight:400;color:#333333;
    }
    .ApplyOpenInvoicessss_fd1_0_c0_c0{
        line-height:45rpx;font-size:32rpx;font-weight:500;color:#333333;
    }
    .ApplyOpenInvoicessss_fd1_0_c0{
        margin:0rpx 32rpx 0rpx 32rpx;padding:32rpx 0rpx 32rpx 20rpx;
    }
    .ApplyOpenInvoicessss_fd1_0{
        background:var(--benbenbgColor1);background-size:100% auto !important;margin:0rpx 0rpx 150rpx 0rpx;
    }
</style>